package com.geolab.controller;

import com.geolab.pojo.ResponseResult;
import com.geolab.pojo.sand.SandLoadTestRecords;
import com.geolab.pojo.sand.SandLoadTestResults;
import com.geolab.pojo.sand.SandSleeveFriction;
import com.geolab.pojo.sand.SandTipResistance;
import com.geolab.service.ResponseResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "/sand/extra")
public class SandExtraDataController {

    @Autowired
    private ResponseResultService resultService;

    @RequestMapping(value = "/querySandQcById", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult<List<SandTipResistance>> selectSandQcById(@RequestParam("ID") Integer ID){
        ResponseResult<List<SandTipResistance>> result;
        if (ID == null || ID <= 0){
            result = new ResponseResult<>(false,"输入的数据ID有误",null);
        }else {
            result = resultService.querySandQcById(ID);
            if (!result.isSuccess()){
                System.out.println("按ID查询Sand_Qc失败");
            }
            if(result.getData().size() == 0){
                result = new ResponseResult<>(true,"参数正确，但数据库中无该id对应的数据",null);
            }
        }
        return result;
    }

    @RequestMapping(value = "/querySandFsById", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult<List<SandSleeveFriction>> selectSandFsById(@RequestParam("ID") Integer ID){
        ResponseResult<List<SandSleeveFriction>> result;
        if (ID == null || ID <= 0){
            result = new ResponseResult<>(false,"输入的数据ID有误",null);
        }else {
            result = resultService.querySandFsById(ID);
            if (!result.isSuccess()){
                System.out.println("按ID查询Sand_Fs失败");
            }
            if(result.getData().size() == 0){
                result = new ResponseResult<>(true,"参数正确，但数据库中无该id对应的数据",null);
            }
        }
        return result;
    }

    @RequestMapping(value = "/querySandLoadById", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResult<List<SandLoadTestResults>> selectSandLoadById(@RequestParam("ID") Integer ID){
        ResponseResult<List<SandLoadTestResults>> result;
        if (ID == null || ID <= 0){
            result = new ResponseResult<>(false,"输入的数据ID有误",null);
        }else {
            result = resultService.querySandLoadResultsById(ID);
            if (!result.isSuccess()){
                System.out.println("按ID查询Sand_LoadResults失败");
            }
            if(result.getData().size() == 0){
                result = new ResponseResult<>(true,"参数正确，但数据库中无该id对应的数据",null);
            }
        }
        return result;
    }
}
